package com.shd.edanpei.presenter;

import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.base.network.rx.BaseObserver;
import com.shd.edanpei.base.network.rx.RxTransformer;
import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.bean.UserModel;
import com.shd.edanpei.presenter.contract.CompanyInfoContract;
import com.shd.edanpei.db.DaoManager;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by mc on 2018/10/25.
 * yang-wen-wen
 */

public class CompanyInfoPresenter extends BasePresenterImpl<CompanyInfoContract.CompanyInfoIView>
        implements CompanyInfoContract.CompanyInfoIPresenter {

    public CompanyInfoPresenter(CompanyInfoContract.CompanyInfoIView mView) {
        super(mView);
    }

    @Override
    public void getData() {
        mBaseIView.showLoading("");
        ApiCreator.getApi().getUser(DaoManager.getInstance().getUserBean().getId())
                .compose(RxTransformer.<UserModel>errorHandle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<UserModel>() {
                    @Override
                    protected void onSuccess(UserModel model) {
                        mBaseIView.setData(model.getCompanyInfo());
                    }

                    @Override
                    public void onFinish() {
                        mBaseIView.stopLoading();
                    }
                });


    }

}
